package com.lanou.service.impl;

import com.lanou.service.ShowGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by QuChao on 2018/11/30
 */
@Service
public class ShowGoodsServiceImpl implements ShowGoodsService {
    @Autowired
    private JedisPool jedisPool;

    @Override
    public List<Map<String, Object>> findAll() {
        return null;
    }

    @Override
    public void setItemId() {
        Integer count = 0;
        Jedis jedis = jedisPool.getResource();
        Set<String> keys = jedis.keys("item*");
        jedis.close();
        for (String key : keys) {
            Jedis resource = jedisPool.getResource();
            count++;
            String id = key.split("em")[1];
            resource.set("itemId" + count, id);
            resource.close();
            System.out.println("第" + count + "条");
        }
        System.out.println("完毕");
    }
}
